﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace NJL.WebUsers
{
    public partial class RegisterBind : BasePage
    {
        NJL.BLL.NJL_USER bllUser = new BLL.NJL_USER();
        NJL.Model.NJL_USER modelUser = new Model.NJL_USER();
        NJL.BLL.NJL_PERSON bllPerson = new BLL.NJL_PERSON();
        NJL.Model.NJL_PERSON modelPerson = new Model.NJL_PERSON();
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void btnSubmitEmail_Click(object sender, EventArgs e)
        {
            if (UserType == "0")
            {
                if (bllUser.GetEmailPhoneByEmail(txtEmail.Text.Trim()))
                {
                    Royalsoft.Common.MessageBox.Show(this, "电子邮件地址已经注册");
                    return;
                }
                modelUser = bllUser.GetModel(UserId);
                modelUser.EMAIL = txtEmail.Text.Trim();
                modelUser.USER_PASSWORD = txtPwdEmail.Text.Trim();
                modelUser.USER_PASSWORD_MD5 = hidPasswordCellEmail.Value;
                modelUser.TYPE_CODE = "2";
                if (bllUser.Update(modelUser))
                {
                    Session["usertype"] = modelUser.TYPE_CODE;
                    modelPerson.ID = DateTime.Now.ToString("yyyyMMddHHmmssfff") + new Random().Next(100, 999).ToString();
                    modelPerson.NJL_SYS_BASE_ID = WEBSITE_CODE;
                    modelPerson.CREATE_DATE_TIME = DateTime.Now;
                    modelPerson.NJL_USER_ID = UserId;
                    if (bllPerson.Add(modelPerson))
                    {
                        if (Session["url"] != null)
                        {
                            Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>window.location.href='" + Session["url"] + "'</script>");
                        }
                        else if (Session["secondurl"] != null)
                        {
                            Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>top.window.location='" + Session["secondurl"] + "'</script>");
                        }
                        else
                        {
                            Response.Redirect("~/AdminVisitor/Default.aspx");
                        }
                    }
                }
            }
        }
    }
}